/*
 * @Descripttion : popup 构造函数 (子集：dialog)
 * @Versions     : 0.1
 * @Author       : foxui team
 * @Date         : 2022-03-08 22:09:18
 * @LastEditors  : QianFox Team
 * @LastEditTime : 2022-06-01 09:57:21
 */

import { _zIndex } from './common/variables';

let indexList = [];

function Popup() {
    this.MODAL_MASK = 'body > .foxui-modal-mask';
}

Popup.prototype._appednMask = function () {
    let zIndex = _zIndex();
    if (indexList.length < 1) {
        let html = `<div class="foxui-modal-mask" tabindex="0" style="display:none; position:fixed; top:0; right:0; bottom:0; left:0; background-color:rgba(0, 0, 0, 0.5); z-index:${zIndex}"></div>`;
        $('body').append(html);
        $(this.MODAL_MASK).fadeIn('fast');

        // 设置 body hidden
        $('body').css('overflow', 'hidden');
    } else {
        $(this.MODAL_MASK).css('z-index', zIndex);
    }
    // 保存 z-index
    indexList.push(zIndex);
};

/**
 * @description: 删除遮罩层
 * @param {*}
 * @return {*}
 * @Date: 2022-03-09 13:29:52
 */
Popup.prototype._deleteMask = function () {
    indexList.pop();
    if (indexList.length > 0) {
        $(this.MODAL_MASK).css('z-index', indexList[indexList.length - 1]);
    } else {
        $(this.MODAL_MASK).fadeOut('fast', function () {
            $(this).remove();

            // 设置 body auto
            $('body').css('overflow', 'auto');
        });
    }
};

export { Popup };
